package com.group2.view;
import static model.netBase.IP;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.*;
import javax.swing.border.EmptyBorder;


import java.awt.event.*;
import java.io.IOException;
import javax.swing.GroupLayout.Alignment;
import model.*;
public class LibraryMainFrame_Student extends JFrame implements ActionListener{

	private JPanel contentPane;
	private static String studentId;
	private JLabel picture;
	private Timer timer;
	private LibraryBookBorrowFrame libraryBookBorrow= null;
	private LibraryBookReturnFrame libraryBookReturnFrame= null;


	/**
	 * Launch the application.
	 */
//	public static void main(String[] args) {
//		EventQueue.invokeLater(new Runnable() {
//			public void run() {
//				try {
//					String currentName = null;
//					LibraryMainFrame_Student frame = new LibraryMainFrame_Student("abc");
//					frame.setVisible(true);
//				} catch (Exception e) {
//					e.printStackTrace();
//				}
//			}
//		});
//	}

	public LibraryMainFrame_Student(String id, Timer time) {
		studentId=id;
		timer=time;
		setTitle("图书馆学生主界面");
		setBounds(400, 100, 605, 498);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);
		time.start();
		this.addMouseMotionListener(new MouseMotionListener() {@Override public void mouseDragged(MouseEvent e) {}@Override public void mouseMoved(MouseEvent e) {time.stop();}});
		this.addMouseListener(new MouseListener() {@Override public void mouseClicked(MouseEvent e) {}@Override public void mousePressed(MouseEvent e) {}@Override public void mouseReleased(MouseEvent e) {}@Override public void mouseEntered(MouseEvent e) {time.start();}@Override public void mouseExited(MouseEvent e) {time.start();}});
		this.addWindowListener(new WindowListener() {
			@Override
			public void windowOpened(WindowEvent e) {

			}

			@Override
			public void windowClosing(WindowEvent e) {

			}

			@Override
			public void windowClosed(WindowEvent e) {
				if(libraryBookBorrow!=null) libraryBookBorrow.dispose();
				if(libraryBookReturnFrame!=null) libraryBookReturnFrame.dispose();
			}

			@Override
			public void windowIconified(WindowEvent e) {

			}

			@Override
			public void windowDeiconified(WindowEvent e) {

			}

			@Override
			public void windowActivated(WindowEvent e) {

			}

			@Override
			public void windowDeactivated(WindowEvent e) {

			}
		});

		JButton btnNewButton = new JButton("图书借阅");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					libraryBookBorrow = new LibraryBookBorrowFrame(studentId,time);
				} catch (IOException ex) {
					throw new RuntimeException(ex);
				} catch (ClassNotFoundException ex) {
					throw new RuntimeException(ex);
				}
				libraryBookBorrow.setVisible(true);
			}
			
		});
		menuBar.add(btnNewButton);
		
		JButton btnNewButton_1 = new JButton("图书归还");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				try {
					libraryBookReturnFrame = new LibraryBookReturnFrame(studentId,time);
				} catch (IOException ex) {
					throw new RuntimeException(ex);
				} catch (ClassNotFoundException ex) {
					throw new RuntimeException(ex);
				}
				libraryBookReturnFrame.setVisible(true);
			}
		});
		menuBar.add(btnNewButton_1);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		picture = new JLabel("New label");
		picture.setBounds(0, 0, 591, 436);
		picture.setIcon(new javax.swing.ImageIcon(UserLogOnFrame.class.getResource("/images/图书馆.png")));
		contentPane.add(picture);
	}


	@Override
	public void actionPerformed(ActionEvent e) {
		libraryBookBorrow.dispose();
		libraryBookReturnFrame.dispose();
		timer.stop();
	}
}
